import Loader from "../../../Common/Loader";
import gameConfig from "../../config/gameConfig";
import { mgrs, sers } from "../../system/OverallSystem ";
import gameListItem from "./gameListItem";
import PageBase from "./pageBase";

const { ccclass, property } = cc._decorator;

@ccclass
export default class gameList extends PageBase {

    public pageName: string = "更多游戏";

    @property(cc.Node)
    item: cc.Node = null

    @property(cc.Node)
    scrContent: cc.Node = null
    
    onLoad() {

    }

    start() {

        Loader.loadBundle("Majiang", (res) => {
            Loader.loadBundleRes('Majiang', 'json/guanqia', (res) => {
                console.log(res.json)
                let data = res.json
                if(!this || !this.node)return
                this.initGame(data)
            })
        }, true, true);
        this._init();

    }

    listData = null

    initGame(data) {

        this.scrContent.removeAllChildren()

        for (const key in data) {
            if (Object.prototype.hasOwnProperty.call(data, key)) {
                const element = data[key];
                let item = cc.instantiate(this.item)
                item.parent = this.scrContent
                item.x = 0
                element.key = key
                item.getComponent(gameListItem).setData(element)
            }
        }

    }

    protected _init(): void {

        this.open();
    }

    OnBtnConfirm() {
       
    }

    OnBtnClose() {
        mgrs().soundMgr.playBtnSound();
        this.onlyClose();
    }

    // update (dt) {}
}
